package com.tbynet.jwp.framework.core;

import static com.tbynet.jwp.framework.core.JwpConstants.CODE_SUCCESS;

public class JwpResponse<T> {

    private boolean success;
    private String code;
    private String message;
    private T data;
    private Long timestamp;

    // 私有构造器
    private JwpResponse(boolean success, String code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
        this.timestamp = System.currentTimeMillis();
    }

    // 成功响应
    public static <T> JwpResponse<T> success(T data) {
        return new JwpResponse<>(true, CODE_SUCCESS, "操作成功", data);
    }

    public static <T> JwpResponse<T> success(String message, T data) {
        return new JwpResponse<>(true, CODE_SUCCESS, message, data);
    }

    // 错误响应
    public static <T> JwpResponse<T> error(String code, String message) {
        return new JwpResponse<>(false, code, message, null);
    }

    public static <T> JwpResponse<T> businessError(String code, String message) {
        return new JwpResponse<>(false, code, message, null);
    }

    // getter方法
    public boolean isSuccess() { return success; }
    public String getCode() { return code; }
    public String getMessage() { return message; }
    public T getData() { return data; }
    public Long getTimestamp() { return timestamp; }
}